﻿using Demo.OrderManager.Orders.Dto;

namespace Demo.OrderManager.Orders;

/// <summary>
/// 订单领域对象映射
/// </summary>
public static class OrdersAutoMapperProfile
{
    /// <summary>
    /// 创建订单领域对象映射关系
    /// </summary>
    /// <param name="profile"></param>
    public static void CreateOrdersMapper(this OrderManagerApplicationAutoMapperProfile profile)
    {
        profile.CreateMap<Order, OrderDto>();
        profile.CreateMap<Order, OrderDetailDto>().AfterMap((entity, dto) =>
        {
            if (entity.OrderLines == null) return;
            foreach (var item in entity.OrderLines)
            {
                dto.Products.Add(new ProductCountDto(item.ProductId, item.Count));
            }
        });
    }
}